package com.gxl.DaoImpl;



import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.gxl.Dao.StudentUserDao;
import com.gxl.Entity.Content;
import com.gxl.Entity.StudentUser;
import com.gxl.Entity.User;


public class StudentUserDaoImpl extends HibernateDaoSupport implements StudentUserDao{


	@SuppressWarnings("unchecked")
	public String  InsertStudentUser(StudentUser studentUser)
	{

		String queryString = "from StudentUser  as s WHERE s.studentUserNo = '"+studentUser.getStudentUserNo()+"' AND s.studentUserPassword = '"+studentUser.getStudentUserPassword()+"'";
		List<StudentUser> userlist=getHibernateTemplate().find(queryString);

		if(userlist.size()!=0)
		{

			return "error";
		}
		else
		{
			this.getHibernateTemplate().save(studentUser);
			return "ok";
		}




	}

	@Override
	public StudentUser FindStudentUser(String UserNo, String UserPassword) {

		String queryString = "from StudentUser  as s WHERE s.studentUserNo = '"+UserNo+"' AND s.studentUserPassword = '"+UserPassword+"'";
		List<StudentUser> userlist=getHibernateTemplate().find(queryString);
		if(userlist.size()!=0)
			return userlist.get(0);
		else
			return null;
	}

	@Override
	public List<StudentUser> FindAll() {

		String queryString = "from StudentUser  as s ";
		List<StudentUser> userlist=getHibernateTemplate().find(queryString);
		return userlist;
	}

<<<<<<< HEAD
	@Override
	public void ChangeGroup(String sid, String ssb, String sno, String sname,
			String spassword, String sstate, String change) {

		System.out.println(sid+ssb+sno+sname+spassword+sstate+change);
		StudentUser a= new StudentUser();

		a.setStudentUserId(sid);
		a.setStudentUserSb(ssb);
		a.setStudentUserNo(sno);
		a.setStudentUserName(sname);
		a.setStudentUserPassword(spassword);
		a.setStudentUserState(sstate);
		a.setStudentUserGroup(change);


		this.getHibernateTemplate().update(a);

=======

	@Override
	public void ChangeGroup(String sid, String change) {

		StudentUser user = FindById(sid);
		user.setStudentUserGroup(change);
		this.getHibernateTemplate().update(user);
	}
	public StudentUser FindById(String Id)
	{

		String queryString = "from StudentUser  as s where studentUserId =' "+Id+"'";
		List<StudentUser> userlist=getHibernateTemplate().find(queryString);
		StudentUser user = userlist.get(0);
		return user;
				
>>>>>>> bcf2400f1f37cc9af755d42c2557f9ec702656e8
	}

}
